home *** CD-ROM | disk | FTP | other *** search
- Path: news1.h1.usa.pipeline.com!usenet
- From: grantp@usa.pipeline.com
- Newsgroups: comp.lang.c++
- Subject: Re: C++ Vs. C & Efficiency
- Date: 12 Jan 1996 14:16:33 GMT
- Organization: Pipeline USA
- Message-ID: <4d5qg1$3fa@news1.usa.pipeline.com>
- NNTP-Posting-Host: pipe11.h1.usa.pipeline.com
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete)
- X-Newsreader: Pipeline USA v3.3.0
-
- On Jan 12, 1996 09:34:03 in article <C++ Vs. C & Efficiency>,
- 'edwint@infomatch.com (Edwin Tam)' wrote:
-
-
- >Hello,
- >
- >I have recently become proficient in C++ programming and was wondering
- about
- >the advantages of C++ vs C. One thing that has always sorta bugged me
- though
- >the question of the extra overhead required by C++ ( compiler wise ).
-
- There's no inherent extra overhead in C++ over C.
-
- >It seems as if every C++ programmer wants to 'object'ize every thing
- without
- >considering the overhead incurred by objects.
- >
- If that was the case -- and it's not -- then the 'blame' belongs to the
- programmer, not the language.
-
- >Has anyone got any opinions or idea of the overhead imposed by C++??
-
- As I already said, none.
-
- >A simple ponder : For every object instance, every variable of that class
- is
- >duplicated... even if its not required.
- >
- Assuming you're referring to non-static members -- yes. Just like in C
- and Pascal and.... you name it. Would you want it any other way?
-
- But here's where the power of C++ comes in: You can define:
-
- class Base { ... variables that all should have };
- class fooDerived : public Base { variables needed also by fooDerived };
- class barDerived : public fooDerived { additional variables needed
- by barDerived };
-
- and select which kind of object to create based on your needs.
- And all this comes at no extra run time cost (over C structures)
- to boot!
-
- The extra "cost" you may be concerned about, has to do with
- virtual functions and virtual derivation. This cost is not
- real as equivalent C code "costs" just as much -- and
- in some cases more -- than the virtual dispatch mechanism of C++.
-
- On the other side of the coin, C++ has inline, while C doesn't.
- This can make C++ code more efficient.
-
- --
-
- Pete
-